<?php

/**
 *      [Discuz!] (C)2001-2099 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: forum_notice.php 6757 2010-03-25 09:01:29Z cnteacher $
 */

return;//noteX;
if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}
define('NOROBOT', TRUE);

if(!$_G['uid']) {
	showmessage('not_loggedin', NULL, array(), array('login' => 1));
}

$filter = !empty($filter) && in_array($filter, $promptkeys) ? $filter : '';
$newexists = 0;
$typeadd = $filter ? "AND typeid='".$prompts[$filter]['id']."'" : "AND typeid IN (".dimplode($promptpmids).")";
$page = max(1, intval($_G['gp_page']));
$start_limit = ($page - 1) * $_G['ppp'];
$pmlist = $ids = array();
$today = TIMESTAMP - (TIMESTAMP + $_G['setting']['timeoffset'] * 3600) % 86400;

$count = DB::result_first("SELECT count(*) FROM ".DB::table('promptmsgs')." WHERE uid='$_G[uid]' $typeadd");
$query = DB::query("SELECT id AS pmid, new, message, dateline, typeid, actor FROM ".DB::table('promptmsgs')." WHERE uid='$_G[uid]' $typeadd ORDER BY dateline DESC LIMIT $start_limit, $_G[ppp]");
while($row = DB::fetch($query)) {
	if($row['new']) {
		$newexists = 1;
	}
	$find = array('{boardurl}', '{time}');
	$replace = array($_G['siteurl'], '<em>'.dgmdate($row['dateline'], 'u').'</em>'.($row['new'] ? '<img src="'.IMGDIR.'/notice_newpm.gif" alt="NEW" />' : ''));
	if(strpos($row['message'], '{actor}') !== FALSE) {
		list($actorcount, $actors) = explode("\t", $row['actor']);
		$actorarray = explode(',', $actors);
		$actor = $comma = '';
		foreach($actorarray as $au) {
			$actor .= $comma.($au != '<i>Anonymous</i>' ? '<a href="home.php?mod=space&username='.rawurlencode($au).'" target="_blank">'.$au.'</a>' : $au);
			$comma = ',';
		}
		if($actorcount > 5) {
			$language = lang('forum/misc');
			$actor .= eval('return " '.$language['notice_actor'].'";');
		} else {
			$actor .= ' ';
		}
		$find[] = '{actor}';
		$replace[] = $actor;

	}
	$row['message'] = str_replace($find, $replace, $row['message']);
	$pmlist[] = $row;
}
if($newexists) {
	DB::query("UPDATE ".DB::table('promptmsgs')." SET new='0' WHERE uid='$_G[uid]' AND new='1'", 'UNBUFFERED');
}
$multipage = multi($count, $_G['ppp'], $page, 'forum.php?mod=notice'.($filter ? '?filter='.$filter : ''));
if(!$filter) {
	foreach($prompts as $promptkey => $promptdata) {
		if($promptdata['new']) {
			updateprompt($promptkey, $_G['uid'], 0);
		}
	}
} elseif($prompts[$filter]['new']) {
	updateprompt($filter, $_G['uid'], 0);
}


include template('forum/notice');

?>